package in.muton.panels.paginator.components.listitems;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.pages.group.GroupPeople;
import in.muton.edushare.url.EduShareURLPanel;
import in.muton.panels.paginator.badgehelpers.course.GroupBadgeInterface;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;

import com.edushare.common.vo.Groups;

public class GroupListItem extends EdusharePanel {
	private IModel<Groups> model;
	private GroupBadgeInterface gbi;

	public GroupListItem(String id, IModel<Groups> model, EduShareBasePage page) {
		super(id, model, page);
		this.setModel(model);
		gbi = new GroupBadgeInterface();
		PageParameters params = new PageParameters();
		params.add("0", getModel().getObject().getGroupId().toString());
		add(new EduShareURLPanel("groupURL", getModel()));
		add(new BookmarkablePageLink<Void>("peopleLink", GroupPeople.class,
				params));
		add(new Link<Void>("delete") {
			private static final long serialVersionUID = 1639366604780941607L;

			@Override
			public void onClick() {
				setError(gbi.removeGroup(GroupListItem.this.getModel()));
			}

			@Override
			public boolean isVisible() {
				return gbi != null
						&& gbi.isAdmin(GroupListItem.this.getModel()
								.getObject());
			}
		});
	}

	public void setModel(IModel<Groups> model) {
		this.model = model;
	}

	public IModel<Groups> getModel() {
		return model;
	}

	private static final long serialVersionUID = -1916452238614292093L;
}
